
cap mkdir "graphs"
cap mkdir "graphs/appendix"
cap mkdir "tables"


/******************************************************************************
*******************************************************************************
*******************************************************************************
Main text
*******************************************************************************
*******************************************************************************
*******************************************************************************/




/******************************************************************************
*******************************************************************************
Tables: 
1) The Test Rejects in Most Industries
2) The Selection Criterion Is Met in Some but Not All Industries Where the Test 
	of Section \ref{sec:test} Rejects
*******************************************************************************
*******************************************************************************/

do "do/prodestcon_testtable.do"


/******************************************************************************
*******************************************************************************
Figure: The Selection Criterion Reduces Error
(Also, appendix figure Non-Autoregressive Productivity Calibrated to Chile's Industry 311 )
*******************************************************************************
*******************************************************************************/


foreach case in "" "_nl" {
	/************************************************************************
	Calculate selection estimators
	************************************************************************/

	use "dta/simulations/sweeps_feasible_widrev`case'.dta", clear


	/********************************
	Infeasible
	*********************************/
		
	foreach fact in k l m {


		gen elas`fact'_inf 		= elas`fact'_gnr
		replace elas`fact'_inf 	= elas`fact'_ar_dem if (elas`fact'_gnr - elas`fact'_tru)^2 > (elas`fact'_ar_dem - elas`fact'_tru)^2
		
		
	}

	/********************************
	Feasible
	*********************************/


	//10 Percent reject
	foreach fact in k l m {
		gen elas`fact'_feaswid10 = elas`fact'_gnr
		replace elas`fact'_feaswid10 = elas`fact'_ar_dem if idtest_share_pval < ${testcutoff} & widstat_iv > widstatp_1 & widstat_iv < .
	}

	//5 Percent reject
	foreach fact in k l m {
		gen elas`fact'_feaswid5 = elas`fact'_gnr
		replace elas`fact'_feaswid5 = elas`fact'_ar_dem if idtest_share_pval < ${testcutoff} & widstat_iv > widstatp_2 & widstat_iv < . 
	}


	/************************************************************************
	Calculate absolute errors
	************************************************************************/
	foreach est in feaswid5 feaswid10 inf ar_dem gnr {
		foreach fact in k l m {
			gen err`fact'_`est' = abs( (elas`fact'_`est' - elas`fact'_tru)/elas`fact'_tru ) * 100
			replace err`fact'_`est' = 100 if mi(err`fact'_`est')
		}
	}


	collapse   err*, by(fraccon)
		
		


	/************************************************************************
	Make Graph
	************************************************************************/

	sum errk_gnr if fraccon == 60
	local gnrheight = r(mean) + 3

	sum errk_inf if fraccon == 50
	local infheight = r(mean) - 5
	
	
	/* Colors
	local colorgnr midblue
	local colorinf black
	local colorfeas10 purple
	local colorfeas5 orange
	*/
	
	//Greyscale
	local colorgnr gs6
	local colorinf black
	local colorfeas10 gs8
	local colorfeas5 gs12
	
	
	foreach sig in 5 10 {
		sum errk_feaswid`sig' if fraccon == 60	
		local feaswidheight`sig' = r(mean) + 3
	}


	local titlek "Capital Elasticity"
	local titlel "Labor Elasticity"
	local titlem "Intermediates Elasticity"

	local ytitlek Mean of Absolute Error (% of True Value)
	
	local labelsl
	local labelsk `"text(`gnrheight' 56 "GNR", color(`colorgnr') size(vlarge) ) text(`infheight' 50 "Infeasible", color(`colorinf') size(vlarge) ) text(`feaswidheight10' 65 "Feasible90", color(`colorfeas10') size(vlarge) ) text(`feaswidheight5' 65 "Feasible95", color(`colorfeas5') size(vlarge) ) "'
	foreach fact in k l m {
		#delimit;
		scatter err`fact'_gnr err`fact'_inf err`fact'_feaswid10 err`fact'_feaswid5 fraccon, 
				ylabel(0(20)100, labsize(large) ) graphregion( color(white) ) legend( off )
				connect(direct direct direct direct) ms(o Sh + Dh) mc(`colorgnr' `colorinf' `colorfeas10' `colorfeas5')
				lc(`colorgnr' `colorinf' `colorfeas10' `colorfeas5') lp(solid longdash shortdash dash_dot)
				xtitle("Percentage of Firm-Years Constrained", size(huge) )
				ytitle("`ytitle`fact''", size(huge) ) xlabel(, labsize(large) )
				`labels`fact'' title("`title`fact''", size(huge) ) name(g`fact')
				;
		#delimit cr
		
	}

	graph combine gk gl gm, graphregion(color(white) fcolor(white) ) rows(1) ysize(1.9)
	graph drop gk gl gm
		
	graph export "graphs/benchmark`case'_allsig.pdf", replace

}




/******************************************************************************
*******************************************************************************
*******************************************************************************
Online-Only Supplement
*******************************************************************************
*******************************************************************************
*******************************************************************************/

/******************************************************************************
*******************************************************************************
Figure: Firms are Constrained in Many Chilean and Colombian Industries
*******************************************************************************
*******************************************************************************/

//Generate share test results
do "do/prodestcon_chile.do"
do "do/prodestcon_colombia.do"

//Form figure
foreach country in chile colombia {

	use "dta/emp_results/`country'.dta", clear


	label define industries 	311 "Food Products" 321 "Textiles" 322 "Apparel" 331 "Wood Products" 381 "Fabricated Metals"
	label values ind industries



	local mlist
	forvalues i=1/7 {
		local mlist `mlist' marker(`i', mc(black) ms(o) ) //gs`i'
	}
	
	local title = proper("`country'")
		
		
	graph dot shtest_pval*, over(ind) linegap(30) graphregion(color(white)) ylabel(0(.2)1) ///
							legend( off)  ///
							 `mlist' marker(8, mc(black) ms(oh) ) marker(9, mc(black) ms(oh) )  ///
							 name(`country') ytitle("p-value") title("`title'") ///
							   yline(0.01, lp(longdash) lc(red) ) yline(0.05, lp(shortdash) lc(gs12) ) ///
							   text(.05 107 "0.05", color(gs12) orientation(vertical) ) text(0.01 107 "0.01", color(red) orientation(vertical) )
}

graph combine chile colombia, graphregion( color(white) fcolor(white) ) xsize(7)
graph drop chile colombia

graph export "graphs/appendix/tests.pdf", replace

/******************************************************************************
*******************************************************************************
Figure: Estimates of the Markov Process for Productivity  for Chilean Industries from Gandhi et al
*******************************************************************************
*******************************************************************************/


use "dta/emp_results/calibration_chile.dta", clear

foreach ind in 311 321 322 331 381 {
	preserve
	keep if ind == `ind'
	local om0 = om0 in 1
	local om1 = om1 in 1
	local om2 = om2 in 1
	local om3 = om3 in 1
	local meanomega = meanomega in 1
	local gen`ind' `om0' - `meanomega' + `om1'*(lagomega+`meanomega') + `om2'*(lagomega+`meanomega')^2 + `om3'*(lagomega+`meanomega')^3
	restore
}

clear
local nom 100
set obs `nom'
gen lagomega = -`nom'/200 + (_n-1)/100

foreach ind in 311 321 322 331 381 {
	gen omega`ind' = `gen`ind''
}

scatter omega* lagomega, connect(direct direct direct direct direct) ms(p p p p p)

local glist
foreach var of varlist omega* {
	local ind = substr("`var'", -3, 3)
	twoway  (lfit `var' lagomega, connect(direct) ms(p) lp(dash) lc(black) lw(thick)) ///
		 (scatter `var' lagomega , connect(direct) ms(i) lp(solid dash) lc(ltblue) lw(thick) ), ///
		name(`var') legend(off) graphregion(color(white)) ///
		ytitle("Productivity") xtitle("Lagged Productivity") title("Industry `ind'")
	local glist `glist' `var'
}

graph combine `glist', graphregion(color(white) fcolor(white))
graph drop `glist'

graph export "graphs/appendix/markov.pdf", replace		


/******************************************************************************
*******************************************************************************
Figure: Estimated Elasticities: Baseline Specification
*******************************************************************************
*******************************************************************************/
use "dta/simulations/sweeps_feasible_widrev.dta", clear
gen spec = 1

//Build up our collapse command
local collapselist ""

//We want the 10th and 90th percentiles (confidence intervals) and the median (estimate)
foreach stat in p10 p50 p90 {
	local collapselist "`collapselist' (`stat')"
	
	//Do this for each elasticity and the sdev(MP)
	foreach var of varlist elas* sdev* {
	
		//We'll call the median by the name of the original variable
		if "`stat'" == "p50" {
			local collapselist "`collapselist' `var'"
		}
		//The percentiles will have _pxx suffixes
		else {
			local collapselist "`collapselist' `var'_`stat'=`var'"
		}
	}
}

collapse `collapselist', by(spec fraccon)

/***** Separate Figures **********/

//Labels for the factor
local mlabel "Intermediates Elasticity"
local klabel "Capital Elasticity"
local llabel "Labor Elasticity"
local xlabl "Percentage of Firm-Years Constrained"


local kcom `"text(.18 50 "GNR", color(blue) size(medlarge) ) text(.075 42 "AR", color(red) size(medlarge) ) text( .107 35 "True", color(black) size(medlarge) ) "' 
foreach factor in  m k l {
	scatter  elas`factor'_gnr* elas`factor'_ar_dem* elas`factor'_tru fraccon if spec == 1, ///
			mc( blue blue blue red red red black ) ms(i i i i i i D ) legend(off) ///
			connect( direct direct direct direct direct direct   none) ///
			sort(fraccon fraccon fraccon fraccon fraccon fraccon  fraccon ) ``factor'com' ///
			lc( blue blue blue red red red black) lp(  dash solid dash dash solid dash ) ///
			graphregion(color(white)) xtitle("Percentage of Firm-Years Constrained", size(large) ) ytitle("Estimates (Median, p10, p90)", size(large) ) 
	
	graph export "graphs/appendix/spec1_`factor'.pdf", replace
			

}





/******************************************************************************
*******************************************************************************
Figures: 
The (Infeasible) rK-Statistic Rises with Constraints
The Test of Section 3 Rejects in the Presence of Constraints
*******************************************************************************
*******************************************************************************/
use "dta/simulations/statlistfull.dta", clear

gen rej5 = pval < .05

collapse widtrue rej5, by(fraccon)



/*********************
Weak Instruments
**********************/
scatter wid fraccon, connect(direct) graphregion(color(white)) ///
		xtitle("Percentage of Firm-Years Constrained", size(vlarge)) ///
		ytitle("Kleibergen-Paap rK Statistic", size(vlarge))


graph export "graphs/appendix/widstat_inf.pdf", replace


/*********************
Rejection rate of test
**********************/
scatter rej5 fraccon, connect(direct) graphregion(color(white)) ///
		xtitle("Percentage of Firm-Years Constrained", size(vlarge)) ///
		ytitle("Rejection Rate (5 Percent Level)", size(vlarge))


graph export "graphs/appendix/testrej.pdf", replace






/************************************************************************
*************************************************************************
Figure:
The Procedure Improves Estimates Even Under Extreme Data Generating Processes
*************************************************************************
************************************************************************/
use "dta/simulations/sweeps_systematicparam_widrev.dta", clear

/************************************************************************
Compute Infeasible Estimator
************************************************************************/
foreach fact in k l m {


	gen elas`fact'_inf 		= elas`fact'_gnr
	replace elas`fact'_inf 	= elas`fact'_ar_dem if (elas`fact'_gnr - elas`fact'_tru)^2 > (elas`fact'_ar_dem - elas`fact'_tru)^2
	
	
}





/************************************************************************
Compute Feasible Estimator
************************************************************************/


//10 Percent reject
foreach fact in k l m {
	gen elas`fact'_feaswid10 = elas`fact'_gnr
	replace elas`fact'_feaswid10 = elas`fact'_ar_dem if idtest_share_pval < ${testcutoff} & widstat_iv > widstatp_1 & widstat_iv < . 
}

//5 Percent reject
foreach fact in k l m {
	gen elas`fact'_feaswid5 = elas`fact'_gnr
	replace elas`fact'_feaswid5 = elas`fact'_ar_dem if idtest_share_pval < ${testcutoff} & widstat_iv > widstatp_2 & widstat_iv < . 
}


foreach sig in 5 10 {
	preserve

	foreach fact in k l m {
		rename elas`fact'_feaswid`sig' elas`fact'_feaswid
	}



	/************************************************************************
	Error
	************************************************************************/

	//Calculate the absolute error of each estimator
	foreach est in gnr ar_dem inf feaswid {
		foreach fact in k l m {
			gen err`fact'_`est' = abs( (elas`fact'_`est' - elas`fact'_tru)/elas`fact'_tru ) * 100
			replace err`fact'_`est' = 100 if mi(err`fact'_`est')
		}
	}



	/************************
	Bias Reduction
	*************************/


	//collapse (mean) err*, by(subspec)

	foreach fact in k l m {
		gen red`fact' = (err`fact'_gnr-err`fact'_feaswid)
	}


	local labels
	local count 0
	foreach title in "Basic" "SD(Innovation) [+]" "SD(Shock) [+]" "AR Coef. on Prod. [+]" "AR(1) Coef. on S [+]" "AR(2) Coef. on S [+]" "SD(Innovation) [-]" "SD(Shock) [-]" "AR Coef. on Prod. [-]" "AR(1) Coef. on S [-]" "AR(2) Coef. on S [-]" {
		
		local labels `labels' `count' "`title'"
		local ++count
	}

	di `"label define subspecs `labels'"'

	cap label drop subspecs
	label define subspecs `labels'
	label values subspec subspecs

	#delimit;
	graph bar red* if subspec < 5, 
	ylabel(-10(10)30)
	over(subspec) xsize(12) graphregion(color(white)) 
	legend(off)
	ytitle("over GNR Alone", size(large))
	name(g1)
	;
	#delimit cr

	#delimit;
	graph bar red* if subspec >= 5, 
	ylabel(-10(10)30)
	over(subspec) xsize(10) graphregion(color(white)) 
	legend(label(1 "Capital") label(2 "Labor") label(3 "Intermediates"))
	ytitle("Feasible Estimator: Avg. Improvement", size(large))
	name(g2)
	;
	#delimit cr



	graph combine g1 g2, graphregion(color(white))  rows(2) xsize(7)
	graph drop g1 g2


	graph export "graphs/appendix/extreme_sig`sig'_summary.pdf", replace
	
	restore

}





/************************************************************************
*************************************************************************
Table:
Absolute Error of Each Estimator when Productivity is Not Autoregressive
*************************************************************************
************************************************************************/
use "dta/simulations/sweeps_nlsim_rev.dta", clear


/********************************
Infeasible
*********************************/
	
foreach fact in k l m {


	gen elas`fact'_inf 		= elas`fact'_gnr
	replace elas`fact'_inf 	= elas`fact'_ar_dem if (elas`fact'_gnr - elas`fact'_tru)^2 > (elas`fact'_ar_dem - elas`fact'_tru)^2
	
	
}

/********************************
Feasible
*********************************/
	
gen arfail = 0
foreach fact in k l m {
	//replace arfail = arfail | (elas`fact'_ar_dem <= 0)
}

//10 Percent reject
foreach fact in k l m {
	gen elas`fact'_feaswid10 = elas`fact'_gnr
	replace elas`fact'_feaswid10 = elas`fact'_ar_dem if idtest_share_pval < ${testcutoff} & widstat_iv > widstatp_1 & widstat_iv < . & arfail == 0
}

//5 Percent reject
foreach fact in k l m {
	gen elas`fact'_feaswid5 = elas`fact'_gnr
	replace elas`fact'_feaswid5 = elas`fact'_ar_dem if idtest_share_pval < ${testcutoff} & widstat_iv > widstatp_2 & widstat_iv < . & arfail == 0
}


/************************************************************************
Calculate absolute errors
************************************************************************/
foreach est in feaswid5 feaswid10 inf ar_dem gnr {
	foreach fact in k l m {
		gen err`fact'_`est' = abs( (elas`fact'_`est' - elas`fact'_tru)/elas`fact'_tru ) * 100
		replace err`fact'_`est' = 100 if mi(err`fact'_`est')
	}
}


collapse   err*, by(fraccon spec)

rename *feaswid5 *feaswid


/******************************
Make Table
*******************************/

local keylist
foreach est in gnr ar_dem feaswid {
	foreach spec in 0 2 4  {
		foreach con in 1 20 60 {
			sum errk_`est' if spec == `spec' & fraccon == `con'
			local `est'_`spec'_`con' = string( r(mean), "%9.1f" )
			
			local keylist `keylist' `est'_`spec'_`con'
		}
	}
}





/********
Output table using template
********/

//Base file:
tempfile desc0
filefilter "templates/nlsim2.txt" "`desc0'", from(" ") to(" ")

//Loop
local onfile = 0
foreach key in `keylist' {
	local tmp = `onfile'+1
	tempfile desc`tmp'
	filefilter "`desc`onfile''" "`desc`tmp''", from("[`key']") to("``key''")
	local onfile = `tmp'
}

//The last temporary file we made is the final version
copy "`desc`tmp''" "tables/nlsim2.tex", replace






/************************************************************************
*************************************************************************
Figure: The Autoregressive Method and Ackerberg-Caves-Frazer
************************************************************************
************************************************************************/

/************************************************************************
Generate the median errors for GNR and the test-guided procedure
************************************************************************/

use "dta/simulations/sweeps_env_va.dta", clear


cap mkdir "graphs/appendix/va"
local graphdir "graphs/appendix/va"


foreach var of varlist elas* sdev* {
	local tmp = regexr("`var'", "_.+", "")
	gen err_`var' = abs( (`var'-`tmp'_tru)/`tmp'_tru ) * 100
}





//Calculate the failure probability
foreach method in acf2 ar {
	gen fail_`method' = mi(err_elask_`method',err_elasl_`method')
}



collapse (median) err* (mean) fail*, by(spec fraccon)

drop *tru





/************************************************************************
Baseline Comparison
************************************************************************/


foreach spec in 1 2 {
	preserve
	//In all of these we want to make sure the graph fits within a range of 0-100
	//percent errors; so we'll make numbers bigger than equal 100
	foreach var of varlist err* {
		replace `var' = min(`var',100)
	}

	//Which statistic?
	local stat elas

	//Labels for the factor
	local klabel "Capital"
	local llabel "Labor"

	//X-axis label; only need to do the bottom graph
	local maxlab "Percentage of Firm-Years Constrained"

	//Labels for each line; this only goes on the middle graph
	local lspeclab `"text( 75 58 "ACF", size(small) color(blue) ) text( 11 65 "AR", size(small) color(red) )  "'
				
	foreach factor in l k {
		#delimit;
		scatter  err_`stat'`factor'_acf2 err_`stat'`factor'_ar fraccon if spec == `spec', 
										legend(off) connect(  direct direct  ) sort(fraccon fraccon  ) 
										lc( blue red ) graphregion(color(white)) mc(blue red)  
										lp(solid dash)  yscale( range(0 100) ) ylabel(0(50)100) lw(medium medthick) 
										title( "``factor'label'", size(medsmall) ) ytitle("Error (%)")  
										xtitle("``factor'axlab'") ``factor'speclab' name(base`factor') ;
		#delimit cr								
	}


	graph combine basel basek, graphregion(fcolor(white) color(white)) rows(2) ysize(5)
	graph drop basel basek

	restore

	graph export "graphs/appendix/va/spec`spec'.pdf", replace

}






/************************************************************************
*************************************************************************
Figures:
The Intensive and Extensive Margin of Constraints Rise Together in the Main Specification
The Selection Method Is Most Effective When Firms Face Severe Constraints (Even if Only a Small Number of Firms Face the Constraint)
The rk-Statistic Is Considerably Less Likely to Reject when Firms Face Light Constraints
*************************************************************************
************************************************************************/


/************************************************************************
***
Calculate relationship between intensive and extensive when using main 
specification for the constraint
***
************************************************************************/
use "dta/simulations/constraint_fractions.dta", clear
gen set = subinstr(conset,"const","",1)
destring set, replace


#d;
graph bar 
uncond_q20 uncond_q40 uncond_q60 uncond_q80 uncond_q100 , 

over(set) stack graphregion( color(white) )
legend( 
	label(1 "0-20%")
	label(2 "20-40%")
	label(3 "40-60%")
	label(4 "60-80%")
	label(5 "80-100%")
	label(6 "Uncon.")
	rows(2)
	)
title("Unconditional") name(g1)
;
#d cr


#d;
graph bar 
cond_q20 cond_q40 cond_q60 cond_q80 cond_q100, 

over(set) stack graphregion( color(white) )
legend( 
	label(1 "0-20%")
	label(2 "20-40%")
	label(3 "40-60%")
	label(4 "60-80%")
	label(5 "80-100%")
	rows(2)
	)
title("Conditional") name(g2)
;
#d cr

graph combine g1 g2, graphregion( color(white) fcolor(white) ) xsize(8)
graph drop g1 g2

graph export "graphs/appendix/intensive_margin_compute.pdf", replace





/************************************************************************
***
Disentangle the impact of intensive versus extensive margin
***
************************************************************************/
use "dta/simulations/sweeps_feasible_bivar2.dta", clear

gen srcsub = regexs(1) if regexm(src,"([0-9]+_[0-9]+)\.dta")
gen extcon = regexs(1) if regexm(srcsub,"([0-9]+)_")
destring extcon, replace
gen harmcon = fraccon/100 * extcon


/************************************************************************
Compare wid stats, etc.
************************************************************************/
gen rejwid = widstat_iv > widstatp_2 & widstat_iv < .

preserve
	collapse rejwid,  by(harmcon fraccon)
	local title45 "Light"
	local title90 "Heavy"

	#d;
		twoway 
			(scatter rejwid harmcon if fraccon == 90, connect(direct) )
			(scatter rejwid harmcon if fraccon == 45, connect(direct) lc(dash) )
			, 
			graphregion(color(white))
			xtitle("Percentage of Firm-Years Constrained", size(vlarge) )
			ytitle("Rejection Rate (5% Level)", size(vlarge) )
			title("Rejection Rate of rk-stat by Intensive Margin Constraint")
			ylabel(0(.25)1) legend(label(1 "Heavy") label(2 "Light") )
		;
	#d cr

restore

graph export "graphs/appendix/intensive_margin_rkreject.pdf", replace


/************************************************************************
Compare Estimators
************************************************************************/

/********************************
Infeasible
*********************************/
	
foreach fact in k l m {


	gen elas`fact'_inf 		= elas`fact'_gnr
	replace elas`fact'_inf 	= elas`fact'_ar_dem if (elas`fact'_gnr - elas`fact'_tru)^2 > (elas`fact'_ar_dem - elas`fact'_tru)^2
	
	
}

/********************************
Feasible
*********************************/
	

//10 Percent reject
foreach fact in k l m {
	gen elas`fact'_feaswid10 = elas`fact'_gnr
	replace elas`fact'_feaswid10 = elas`fact'_ar_dem if idtest_share_pval < ${testcutoff} & widstat_iv > widstatp_1 & widstat_iv < . 
}

//5 Percent reject
foreach fact in k l m {
	gen elas`fact'_feaswid5 = elas`fact'_gnr
	replace elas`fact'_feaswid5 = elas`fact'_ar_dem if idtest_share_pval < ${testcutoff} & widstat_iv > widstatp_2 & widstat_iv < . 
}


/************************************************************************
Calculate absolute errors
************************************************************************/
foreach est in feaswid5 feaswid10 inf ar_dem gnr {
	foreach fact in k l m {
		gen err`fact'_`est' = abs( (elas`fact'_`est' - elas`fact'_tru)/elas`fact'_tru ) * 100
		replace err`fact'_`est' = 100 if mi(err`fact'_`est')
	}
}


collapse   err*, by(harmcon fraccon)

	


/************************************************************************
Make Graphs
************************************************************************/
local title45 "Light"
local title90 "Heavy"

foreach fc in 45 90 {	

	/************************
	Combined p=5 and p=10 graphs
	*************************/
	sum errk_gnr if harmcon == 36  & fraccon == `fc'
	local gnrheight = r(mean) + 6

	sum errk_inf if harmcon == 18 & fraccon == `fc'
	local infheight = r(mean) - 10

	local colorgnr midblue
	local colorinf black
	local colorfeas10 purple
	local colorfeas5 orange

	foreach sig in 5 10 {
		sum errk_feaswid`sig' if harmcon == 36	& fraccon == `fc'
		local feaswidheight`sig' = r(mean) + 3
	}


	local titlek "Capital Elasticity"
	local titlel "Labor Elasticity"
	local titlem "Intermediates Elasticity"

	local ytitlek Mean of Absolute Error (% of True Value)


	if `fc' == 90 {
		local labelsk `"text(`gnrheight' 36 "GNR", color(`colorgnr') size(large) ) text(`infheight' 30 "Infeasible", color(`colorinf') size(large) ) text(`feaswidheight10' 36 "Feasible90", color(`colorfeas10') size(large) ) text(`feaswidheight5' 36 "Feasible95", color(`colorfeas5') size(large) ) "'
	}
	else {
		local labelsk
	}

	foreach fact in k  {
		#delimit;
		scatter err`fact'_gnr err`fact'_inf err`fact'_feaswid10 err`fact'_feaswid5 harmcon if fraccon == `fc', 
				ylabel(0(20)100, labsize(large) ) graphregion( color(white) ) legend( off )
				connect(direct direct direct direct) ms(o Sh + Dh) mc(`colorgnr' `colorinf' `colorfeas10' `colorfeas5')
				lc(`colorgnr' `colorinf' `colorfeas10' `colorfeas5') lp(solid longdash shortdash dash_dot)
				xtitle("Percentage of Firm-Years Constrained", size(vlarge) )
				ytitle("`ytitle`fact''", size(huge) ) xlabel(, labsize(vlarge) )
				`labels`fact'' title("Intensive Margin Constraint: `title`fc''", size(huge) ) name(g`fc')
				;
		#delimit cr
		
	}
}

graph combine g90 g45, graphregion( color(white) fcolor(white) ) rows(1) ysize(2.5)
graph drop g90 g45

graph export "graphs/appendix/intensive_margin_performance.pdf", replace


